{{define "user/apply.html"}}
<!DOCTYPE html>
<html>
	<head>
        {{template "header"}}
	</head>

	<body>
		<div class="weadmin-nav">
            <span class="layui-breadcrumb">
                <a href="/welcome">首页</a>
                <a href="/admin/user/list">用户管理</a>
                <a><cite>分配角色</cite></a>
            </span>
		</div>
		<div class="weadmin-body">
			<form class="layui-form" lay-filter="user_grant">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label for="L_username" class="layui-form-label">
							<span class="we-red">*</span>用户名
						</label>
						<div class="layui-input-inline layui-text">
							{{.user.Username}}
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label for="L_role" class="layui-form-label">
							分配角色
						</label>
						<div class="layui-input-block">
							{{ range $k,$v := .roleList }}
								<label><input type="checkbox" class="roleid default-chk" name="roleid[]" value="{{$v.id}}" {{if eq $v.ischeck "1"}}checked{{end}}  title="{{$v.rolename}}"  lay-ignore>{{$v.rolename}}</label>&nbsp;&nbsp;
							{{ end }}
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<button class="layui-btn fr" lay-filter="grant" lay-submit="">确定</button>
				</div>
			</form>
		</div>
    </body>

    {{template "jsfile"}}
	<script type="text/javascript">
		layui.extend({
			admin: '/static/js/admin',
		});
		layui.use(['jquery', 'form','element', 'admin', 'carousel'], function() {
			var element = layui.element,
				$ = layui.jquery,
				carousel = layui.carousel,
				form = layui.form,
				admin = layui.admin;
			//建造实例
			carousel.render({
				elem: '.weadmin-shortcut'
				,width: '100%' //设置容器宽度
				,arrow: 'none' //始终显示箭头
				,trigger: 'hover'
				,autoplay:false
			});

			//监听提交
			form.on('submit(grant)', function(data){
				var roleids = []
				$("input:checkbox.roleid:checked").each(function(){
					roleids.push(this.value);
				})
				data.field["roleids"]=roleids;
				$.ajax({
					url:'/admin/user/apply/'+'{{.user.Id}}',
					type:'POST',
					data:data.field,
					dataType:'json',
					success: function(result){
						if(result.status){
							layer.msg("更新用户角色成功!",{time:3*1000,icon:1},function(){
								//自动关闭layer
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							})
						}else{
							layer.msg(result.message,{time:6*1000,icon:2})
						}
					}
				})
				return false;
			});
		});
	</script>

</html>
{{end}}